﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Common;
using Nova_DAL;

public partial class Storage_SerachCommandsHis : System.Web.UI.Page
{
    Nova_DAL.DbHelper access = new DbHelper();
    string strSQL = "";
    DbCommand cmd = null;
    DataSet ds = null;
    string strPID = "";


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(hidden.Value))
        {
            bind();
            hidden.Value = "";
        }
        if (!IsPostBack)
        {


            bind();
        }

    }




    /// <summary>
    /// 查询的SQL语句   
    /// </summary>
    /// <returns></returns>
    protected string getSQL()
    {

        strSQL = @"select top 2000 TaskID, 
                   case TaskMode when 1 then '整入'
                   when 2 then '对接入库'
                    when 3 then '整出'
                    when 4 then '对接出库'
                    when 5 then '离线补货'
                    when 6 then '离线拣选'
                    when 7 then '在线补货'
                    when 8 then '在线拣选'
                    when 9 then '移库'
                    when 11 then '在线整出'
                    when 12 then '在线盘点'
                    when 13 then '空托盘入库'
                    when 14 then '空盘离线整出'
                    when 15 then '离线盘点'
                    when 19 then '直行'
                    when 20 then '特殊物料盘点、补货、拣选'
                   else '其他' end  TaskMode, 
                   Tray_ID, PosS_ID, PosE_ID, EquipmentS_ID, EquipmentE_ID, 
                   Mat_Code,Mat_Name,Mat_Num,
                   case FinishResult when 1 then '指令完成'  else '指令删除' end  FinishResult , 
                   case FinishMethod when 0 then '系统操作' when 1 then 'WCS人工操作' else 'WMS人工操作' end  FinishMethod , 
                   FinishTime from TCommandsHis WHERE 1=1 ";

        if (txtTaskID.Text != "")
        {
            strSQL += " AND TaskID = '" + txtTaskID.Text.ToString() + "' ";
        }
        if (txtTrayID.Text != "")
        {
            strSQL += " AND Tray_ID like '%" + txtTrayID.Text.ToString() + "%'";
        }

        if (txtMatCode.Text != "")
        {
            strSQL += " AND Mat_Code = '" + txtMatCode.Text.ToString() + "' ";
        }
        if (txtMatName.Text != "")
        {
            strSQL += " AND Mat_Name like '%" + txtMatName.Text.ToString() + "%'";
        }

        if (txtBTime.Text != "")
        {
            strSQL += " And FinishTime >= convert(datetime,'" + txtBTime.Text.Trim() + "')";
        }
        if (txtETime.Text != "")
        {
            strSQL += " And  FinishTime < dateadd(d,1,convert(datetime,'" + txtETime.Text.Trim() + "'))";
        }

        strSQL += "  Order By FinishTime desc";
        return strSQL;
    }

    /// <summary>
    /// 加载列表数据
    /// </summary>
    protected void bind()
    {
        cmd = access.GetSqlStringCommond(getSQL());
        gv.DataSource = access.ExecuteDataSet(cmd);
        gv.DataBind();

        Nova_Common.GrdvMerge.GroupRows(gv, 2);
        //GroupRows(gv,9);
    }

    /// <summary>
    /// 查询操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
    {
        bind();
    }

    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        this.gv.PageIndex = e.NewPageIndex;
        this.bind();
    }

}
